Hệ thống quản lý bệnh viện bằng C# với mã nguồn
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Threading.Tasks;
9 using System.Windows.Forms;
10 using System.Data.SqlClient;
11
12 namespace HospitalManagementSystemCSharp
13 {
14 public partial class PatientRegistration : Form
15 {
16 public PatientRegistration()
17 {
18 InitializeComponent();
19 }
20
21 private void button1_Click(object sender, EventArgs e)
22 {
23 SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=F:\Sem.4\C# Projects\Trials\HospitalManagementSystemCSharp\HospitalManagementSystemCSharp\hospital.mdf;Integrated Security=True");
24 con.Open();
25 string gen = string.Empty;
26 if (radioButton1.Checked)
27 {
28 gen = "Male";
29 }
30 else
31 {
32 gen = "Female";
33 }
34 try
35 {
36 string str = "INSERT INTO patient(name,gen,age,date,cont,addr,disease,status,r_type,building,r_no,price) VALUES('" + textBox2.Text + "','" + gen + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "','" + textBox8.Text + "','" + textBox10.Text + "','" + textBox9.Text + "','" + textBox11.Text + "','" + textBox12.Text + "'); ";
37
38 SqlCommand cmd = new SqlCommand(str, con);
39 cmd.ExecuteNonQuery();
40 string str1 = "select max(Id) from patient;";
41
42 SqlCommand cmd1 = new SqlCommand(str1, con);
43 SqlDataReader dr = cmd1.ExecuteReader();
44 if (dr.Read())
45 {
46 MessageBox.Show("Patient Information Saved Successfully..");
47 textBox2.Text = "";
48 textBox3.Text = "";
49 textBox4.Text = "";
50 textBox5.Text = "";
51 textBox6.Text = "";
52 textBox7.Text = "";
53 textBox8.Text = "";
54 textBox9.Text = "";
55 textBox10.Text = "";
56 textBox11.Text = "";
57 textBox12.Text = "";
58
59 }
60 }
61 catch (SqlException excep)
62 {
63 MessageBox.Show(excep.Message);
64 }
65 con.Close();
66 }
67
68 private void PatientRegistration_Load(object sender, EventArgs e)
69 {
70 SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=F:\Sem.4\C# Projects\Trials\HospitalManagementSystemCSharp\HospitalManagementSystemCSharp\hospital.mdf;Integrated Security=True");
71 con.Open();
72 string str1 = "select max(id) from patient;";
73
74 SqlCommand cmd1 = new SqlCommand(str1, con);
75 SqlDataReader dr = cmd1.ExecuteReader();
76 if (dr.Read())
77 {
78 string val = dr[0].ToString();
79 if (val == "")
80 {
81 textBox1.Text = "1";
82 }
83 else
84 {
85 int a;
86 a = Convert.ToInt32(dr[0].ToString());
87 a = a + 1;
88 textBox1.Text = a.ToString();
89 }
90 }
91 con.Close();
92 }
93
94 private void button2_Click(object sender, EventArgs e)
95 {
96 textBox2.Text = "";
97 textBox3.Text = "";
98 textBox4.Text = "";
99 textBox5.Text = "";
100 textBox6.Text = "";
101 textBox7.Text = "";
102 textBox8.Text = "";
103 textBox9.Text = "";
104 textBox10.Text = "";
105 textBox11.Text = "";
106 textBox12.Text = "";
107 textBox1.Text = "";
108 }
109 }
110 }